#ifndef THREAD_SEARCH_VIEW_H
#define THREAD_SEARCH_VIEW_H

#include <wx/string.h>
#include <wx/thread.h>
#include <wx/timer.h>
#include <wx/dynarray.h>
#include <wx/datetime.h>
#include <wx/panel.h>
#include <wx/arrstr.h>
#include "editormanager.h"
#include "M_Code_project.h"
#include "projectmanager.h"
#include "ThreadSearchLoggerBase.h"

class wxToolBar;
class wxStaticBox;
class wxComboBox;
class wxButton;
class wxStaticText;
class cbStyledTextCtrl;
class wxPanel;
class wxMouseEvent;
class wxCommandEvent;
class wxSplitterEvent;
class wxScintillaEvent;
class wxContextMenuEvent;
class wxSplitterWindow;
class wxStaticBoxSizer;
class wxBoxSizer;
class wxBitmap;
class wxBitmapButton;
class wxStaticLine;
class wxImageList;
class ThreadSearch;
class ThreadSearchEvent;
class ThreadSearchThread;
class ThreadSearchFindData;
class SearchInPanel;
class DirectoryParamsPanel;

class ThreadSearchView: public wxPanel {
    friend class ThreadSearch;
  public:
    ThreadSearchView( ThreadSearch& threadSearchPlugin );
    ~ThreadSearchView();
    void ThreadedSearch( const ThreadSearchFindData& aFindData );
    bool IsSearchRunning();
    void OnThreadExit();
    void Update();
    bool UpdatePreview( const wxString& file, long line );
    void SetSashPosition( int position, const bool redraw = true );
    int  GetSashPosition() const;
    void SetSearchHistory( const wxArrayString& searchPatterns, const wxArrayString& searchDirs, const wxArrayString& searchMasks );
    wxArrayString GetSearchHistory() const;
    wxArrayString GetSearchDirsHistory() const;
    wxArrayString GetSearchMasksHistory() const;
    void SetLoggerType( ThreadSearchLoggerBase::eLoggerTypes lgrType );
    void PostThreadSearchEvent( const ThreadSearchEvent& event );
    void SetToolBar( wxToolBar* pToolBar ) {m_pToolBar = pToolBar;}
    wxString GetImagePrefix() const;
    void UpdateOptionsButtonImage( const ThreadSearchFindData &findData );
    void ShowSearchControls( bool show );
    void ApplySplitterSettings( bool showCodePreview, long splitterMode );
    void FocusSearchCombo( const wxString &searchWord );
  private:
    void set_properties();
    void do_layout();
    bool ClearThreadSearchEventsArray();
    bool StopThread();
    void SetMarkerStyle( int marker, int markerType, wxColor fore, wxColor back );
    void UnderlineFoldedLines( bool underline );
    void SetFoldingIndicator();
    ThreadSearchThread* m_pFindThread;
    ThreadSearch& m_ThreadSearchPlugin;
    wxString m_PreviewFilePath;
    wxDateTime m_PreviewFileDate;
    wxMutex m_MutexSearchEventsArray;
    wxArrayPtrVoid m_ThreadSearchEventsArray;
    wxTimer m_Timer;
    long m_StoppingThread;
  protected:
    wxStaticBox* m_pSizerSearchDirItems_staticbox;
    wxComboBox* m_pCboSearchExpr;
    wxBitmapButton* m_pBtnSearch;
    wxBitmapButton* m_pBtnOptions;
    wxStaticLine* m_pStaticLine1;
    wxStaticText* m_pStaTxtSearchIn;
    SearchInPanel* m_pPnlSearchIn;
    wxStaticLine* m_pStaticLine2;
    wxBitmapButton* m_pBtnShowDirItems;
    DirectoryParamsPanel* m_pPnlDirParams;
    M_Code_StyledTextCtrl* m_pSearchPreview;
    wxPanel* m_pPnlPreview;
    ThreadSearchLoggerBase* m_pLogger;
    wxPanel* m_pPnlListLog;
    wxSplitterWindow* m_pSplitter;
    wxStaticBoxSizer* m_pSizerSearchDirItems;
    wxBoxSizer* m_pSizerSearchItems;
    wxToolBar* m_pToolBar;
    DECLARE_EVENT_TABLE()
    void AddExpressionToSearchCombos( const wxString& expression, const wxString& path, const wxString& mask );
    enum eSearchButtonLabel {
      search,
      cancel,
      skip
    };
    void UpdateSearchButtons( bool enable, eSearchButtonLabel label = skip );
    void EnableControls( bool enable );
  public:
    void OnThreadSearchErrorEvent( const ThreadSearchEvent& event );
    void OnCboSearchExprEnter( wxCommandEvent &event );
    void OnBtnSearchClick( wxCommandEvent &event );
    void OnBtnOptionsClick( wxCommandEvent &event );
    void OnBtnShowDirItemsClick( wxCommandEvent &event );
    void OnSplitterDoubleClick( wxSplitterEvent &event );
    void OnShowOptionsDialog( wxCommandEvent &event );
    void OnQuickOptions( wxCommandEvent &event );
    void OnQuickOptionsUpdateUI( wxUpdateUIEvent &event );
    void OnMarginClick( wxScintillaEvent& event );
    void OnContextMenu( wxContextMenuEvent& event );
    void OnLoggerClick( const wxString& file, long line );
    void OnLoggerDoubleClick( const wxString& file, long line );
    void OnBtnSearchOpenFiles( wxCommandEvent &event );
    void OnBtnSearchTargetFiles( wxCommandEvent &event );
    void OnBtnSearchProjectFiles( wxCommandEvent &event );
    void OnBtnSearchWorkspaceFiles( wxCommandEvent &event );
    void OnBtnSearchDirectoryFiles( wxCommandEvent &event );
    void OnTmrListCtrlUpdate( wxTimerEvent& event );
};

#endif
